function [testnum_result,Accuracy,ErRate,Averaged_TimeperTest,RecHistory]=...
    Mugnet_testing(ImgFormat,TestData_Spec,TestLabels_Spec,...
    TestData_Spat,test_num,spec_Weight,spat_Weight,models,PCANet)

fprintf('\n ====== MugNet Testing ======= \n')

TestData_ImgCell_Spec = mat2imgcell(TestData_Spec,1,200,ImgFormat); % convert columns in TestData to cells
TestData_ImgCell_Spat = mat2imgcell(TestData_Spat,9,200,ImgFormat);

clear TestData_Spec;
clear TestData_Spat;

nTestImg = length(test_num);
RecHistory = zeros(nTestImg,1);

tic;
%Spec_testing_data
for j=1:3%Multi-graining
    ftest_spec = PCANet_FeaExt_Spec(TestData_ImgCell_Spec,spec_Weight{j},PCANet,j); % extract a test feature using trained PCANet model
    if j==1
        f_t_spec=ftest_spec;
    else
        f_t_spec=[f_t_spec;ftest_spec];
    end
end
%Spat_testing_data
for k=1:3
    ftest_spat = PCANet_FeaExt_Spat(TestData_ImgCell_Spat,spat_Weight{k},PCANet,k);% extract a test feature using trained PCANet model
    if k==1
        f_t_spat=ftest_spat;
    else
        f_t_spat=[f_t_spat;ftest_spat];
    end
end

ftest=[f_t_spec;f_t_spat];%concacate
[testnum_result, accuracy, decision_values] = predict(TestLabels_Spec,...
    sparse(ftest'), models, '-q'); % label predictoin by libsvm

clear TestData_ImgCell_Spec;
clear TestData_ImgCell_Spat;

RecHistory = testnum_result==TestLabels_Spec;
Accuracy=mean(testnum_result==TestLabels_Spec);
Averaged_TimeperTest = toc/nTestImg;
ErRate = 1 - Accuracy;
end